package com.jt.controller;

import org.springframework.stereotype.Controller;


import org.springframework.ui.Model;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.servlet.ModelAndView;

@Controller
public class UserController {
    @RequestMapping("/findUser")
    public String findUser(String name){

        //return "forward:/findDog";//转发另一个请求，并且携带数据，用户浏览器的地址不会发生改变
        return "redirect:/findDog";//重定向到另一个请求，不能携带数据，用户浏览器的地址会发生改变
    }
    @RequestMapping("/findDog")
    public String findDog(String name,Model model){
        System.out.println(name);
        model.addAttribute("name", name);
        return "dog";
    }


    @RequestMapping("/user")
    public String toUser(Model model){
        model.addAttribute("id", 1003);
        model.addAttribute("name", "孙尚香");
        return "user";
    }



//    @RequestMapping("/user")
//    public ModelAndView toUser(){
//        ModelAndView modelAndView = new ModelAndView();
//        modelAndView.addObject("id", 1001);
//        modelAndView.addObject("name", "安其拉");
//        modelAndView.setViewName("user");
//        return modelAndView;
//
//    }
}
